package com.pactera.chat.mapper.util;

import java.io.IOException;
import java.io.Reader;

import javax.faces.application.Resource;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * @author s-team_zhang
 * @version 1.0 
 */
public class MybatisUtils {
	private static SqlSessionFactory sessionFactory;
	
	private static Reader reader;
	
	static{
		try {
			String configFiles = "mybatis-config.xml";
			reader = Resources.getResourceAsReader(configFiles);
			sessionFactory = new SqlSessionFactoryBuilder().build(reader);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static SqlSession getInstance() {
        return sessionFactory.openSession();
    }
}
